
$(function () {
    $("#regist_button").click(function () {

        var username = $("#regist_username").val()
        var nickname = $("#nickname").val()
        var password = $("#regist_password").val()

        $.ajax({
            url: "/note/user/register.action",
            data: {"username": username, "nickname": nickname, "password": password},
            type: "post",
            dataType: "json",
            success: function (result) {

                if (result.status == 200) {


                    $("#back").click();
                }else {
                    alert(result.mes);
                }
            },
            error: function () {

            }

        })
    })

    $("#login").click(function () {

        $("#user_msg").html("");
        $("#password_msg").html("");

        var count = $("#count").val()
        var password = $("#password").val()
        if (count==""){
            $("#user_msg").html("用户名不能为空")
        }
        if (password==""){
            $("#password_msg").html("密码不能为空")
        }


        $.ajax({

            url: "/note/user/login.action",
            data: {"username":count,"password":password},
            type: "post",
            dataType: "json",
            success:function (result) {
                //&& (result.mes.replace(/^\s+|\s+$/g, "" )) == "成功"
                if (result.status == 200) {
                    addCookie("userId",result.data.user_id,10);
                    location.href = "/note/edit.html";
                }else{
                    alert(result.mes);

                }
            },
            error:function () {

            }

        })

    })


})

